﻿// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)

Shader "GJ/Progress" {
Properties {
    [PerRendererData] _MainTex ("Main Texture", 2D) = "black" {}
    _Color ("Main Color", Color) = (1,1,1,1)
    _ProgressTex ("Progress Texture", 2D) = "black" {}
    _Progress("Progress",Range(0,1)) = 0.5
}
SubShader {
    Tags { "RenderType"="Transparent" }
	Blend SrcAlpha OneMinusSrcAlpha
    LOD 100

    Pass
    {
        CGPROGRAM
        #pragma vertex vert
        #pragma fragment frag
        #include "UnityCG.cginc"

        struct appdata
        {
            float4 vertex : POSITION;
            float4 color    : COLOR;
            float2 uv : TEXCOORD0;
        };

        struct v2f
        {
            float2 uv : TEXCOORD0;
            float4 color    : COLOR;
            float4 vertex : SV_POSITION;
        };

        float4 _Color;
        sampler2D _MainTex;
        sampler2D _ProgressTex;
        float4 _MainTex_ST;
        float4 _ProgressTex_ST;
        float _Progress;

        v2f vert (appdata v)
        {
            v2f o;
            o.vertex = UnityObjectToClipPos(v.vertex);
            o.uv = TRANSFORM_TEX(v.uv, _MainTex);
            o.color = v.color * _Color;
            return o;
        }

        fixed4 frag (v2f i) : SV_Target
        {
            float4 col = tex2D(_MainTex, i.uv);
            float4 progressCol = tex2D(_ProgressTex, i.uv);
            if (progressCol.a <= _Progress && _Progress != 0)
                col = col * i.color;
            else
                col.a = 0;
            return col;
        }
        ENDCG
    }
}

}